import { NEmpty } from "naive-ui";
import type { EmptyProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type EmptyFactoryConstructorType = {
  props?: EmptyProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
  extraSlot?: BaseComponentType;
  iconSlot?: BaseComponentType;
};
export class EmptyFactory {
  private props: EmptyProps = {};
  private attrs: HTMLAttributes = {};
  private defaultSlot: BaseComponentType = null;
  private extraSlot: BaseComponentType = null;
  private iconSlot: BaseComponentType = null;
  constructor(data?: EmptyFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
    if (data?.extraSlot) this.setExtra(data.extraSlot);
    if (data?.iconSlot) this.setIcon(data.iconSlot);
  }

  setProps(props: EmptyProps) {
    this.props = props;
    return this;
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setDefault(defaultSlot: BaseComponentType) {
    this.defaultSlot = defaultSlot;
    return this;
  }
  setExtra(extraSlot: BaseComponentType) {
    this.extraSlot = extraSlot;
    return this;
  }
  setIcon(iconSlot: BaseComponentType) {
    this.iconSlot = iconSlot;
    return this;
  }
  create() {
    return (
      <NEmpty {...this.props} {...this.attrs}>
        {{
          default: this.defaultSlot
            ? () => getSlotsDom(this.defaultSlot)
            : null,
          extra: this.extraSlot ? () => getSlotsDom(this.extraSlot) : null,
          icon: this.iconSlot ? () => getSlotsDom(this.iconSlot) : null,
        }}
      </NEmpty>
    );
  }
}
